package com.egao.orderB.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.gzh.service.GzhGetQRcode;
import com.egao.orderB.entity.Settings;
import com.egao.orderB.service.SettingsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 设置
 * @author : Doman
 * @date : 2020-12-16 16:28:34
 * @version ：1.0
 */

@Api(tags = "设置")
@RestController
@RequestMapping("/api/orderB/settings")
public class SettingsController extends BaseController {

	@Autowired
	private SettingsService settingsService;

	/**
	 * 分页查询列表
	 */
    @ApiOperation(value ="得到公众号ticket",notes = "" +
            "userId:用户id\n" +
            "",httpMethod = "POST")
    @PostMapping("/getTempTicket")
    public JsonResult getTempTicket(PageResult2<T> page,String userId) throws Exception{
        return JsonResult.ok().setData(GzhGetQRcode.getQRcodeTicket("userId="+userId));
    }

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('orderB:settings:list')")
    //@OperLog(value = "设置", desc = "分页查询")
    @ApiOperation(value ="分页查询设置",notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            "name: 名称\n" +
            "englishName: 英文名称\n" +
            "type: 类型 \n" +
            "传值exchange_rate 美元汇率\n" +
            "传值oil_price 油价\n" +
            "传值dock_type 港口\n" +
            "传值sealedLand 加封地\n" +
            "传值applyLand 报关地\n" +
            "传值oceanPort 海运国外港口\n" +
            "传值ship 船公司\n" +
            " \n\n\n" +
            "id:id\n" +
            "name: 名称\n" +
            "type: 类型\n" +
            "value: 值\n" +
            "",httpMethod = "POST")
    @ApiPageParam
    @PostMapping("/list")
    public JsonResult page(PageResult2<T> page, Settings settings) throws Exception{
        return settingsService.list(page, settings, getLoginUser());
    }

    /**
     * 查询全部设置
     */
    @PreAuthorize("hasAuthority('orderB:settings:list')")
    //@OperLog(value = "设置", desc = "查询全部")
    @ApiOperation("查询全部设置")
    @PostMapping("/listAll")
    public JsonResult list(Settings settings){
        return settingsService.list(settings, getLoginUser());
    }

    /**
     * 根据id查询设置
     */
    @PreAuthorize("hasAuthority('orderB:settings:list')")
    //@OperLog(value = "设置", desc = "根据id查询")
    @ApiOperation("根据id查询设置")
    @PostMapping("/get")
    public JsonResult get(Settings settings) {
        return settingsService.getById(settings);
		// 使用关联查询
        //PageParam<settings> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<settings> records = settingsService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }

    /**
     * 添加设置
     */
    @PreAuthorize("hasAuthority('orderB:settings:save')")
    @OperLog(value = "设置", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加设置",notes = "" +
            "name: 名称\n" +
            "englishName: 英文名称\n" +
            "type: 类型 必填\n" +
            "value: 值\n" +
            "传值exchange_rate 美元汇率\n" +
            "传值oil_price 油价\n" +
            "传值dock_type 港口\n" +
            "传值sealedLand 加封地\n" +
            "传值oceanPort 海运国外港口\n" +
            "传值ship 船公司\n" +
            "",httpMethod = "POST")
    @PostMapping("/save")
    public JsonResult save(Model model, Settings settings) {
        return settingsService.save(settings, getLoginUser());
    }

    /**
     * 修改设置
     */
    @PreAuthorize("hasAuthority('orderB:settings:update')")
    @OperLog(value = "设置", desc = "修改", param = false, result = true)
    @ApiOperation(value ="修改设置",notes = "" +
            "name: 名称\n" +
            "englishName: 英文名称\n" +
            "type: 类型 必填\n" +
            "value: 值\n" +
            "传值exchange_rate 美元汇率\n" +
            "传值oil_price 油价\n" +
            "传值dock_type 港口\n" +
            "传值sealedLand 加封地\n" +
            "传值oceanPort 海运国外港口\n" +
            "传值ship 船公司\n" +
            "",httpMethod = "POST")
    @PostMapping("/update")
    public JsonResult update(Model model, Settings settings) {
        return settingsService.update(settings, getLoginUser());
    }

    /**
     * 修改设置
     */
    @PreAuthorize("hasAuthority('orderB:settings:update')")
    @OperLog(value = "设置油价", desc = "修改", param = false, result = true)
    @ApiOperation(value ="设置油价",notes = "" +
            "value 油价\n" +
            "",httpMethod = "POST")
    @PostMapping("/updateOilFee")
    public JsonResult updateOilFee(Model model, Settings settings) {
        settings.setId("4");
        return settingsService.updateOilFee(settings, getLoginUser());
    }

    /**
     * 删除设置
     */
    @PreAuthorize("hasAuthority('orderB:settings:remove')")
    @OperLog(value = "设置", desc = "删除", result = true)
    @ApiOperation("删除设置")
    @PostMapping("/remove")
    public JsonResult remove(Settings settings ) {
        return settingsService.remove(settings, getLoginUser());
    }

    /**
     * 批量添加设置
     */
    /**@RequiresPermissions("orderB:settings:save")
    @OperLog(value = "设置", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<Settings> list) {
        if (settingsService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改设置
     */
    /**@RequiresPermissions("orderB:settings:update")
    @OperLog(value = "设置", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<Settings> batchParam) {
        if (batchParam.update(settingsService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除设置
     */
    /**@RequiresPermissions("orderB:settings:remove")
    @OperLog(value = "设置", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (settingsService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
